package com.example.demo.web.common.filter;

import lombok.extern.slf4j.Slf4j;
import org.dromara.hutool.core.text.StrUtil;
import org.noear.solon.annotation.Component;
import org.noear.solon.core.handle.Context;
import org.noear.solon.core.handle.Filter;
import org.noear.solon.core.handle.FilterChain;

/**
 * @author airhead
 */
@Slf4j
@Component(tag = "adminApi", delivered = false, index = 0)
public class AdminTokenFilter implements Filter {
  @Override
  public void doFilter(Context ctx, FilterChain chain) throws Throwable {
    String token = ctx.header("token");
    if (StrUtil.isBlank(token)) {
      throw new RuntimeException("token 不能为空");
    }

    chain.doFilter(ctx);
  }
}
